﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;

namespace RestClient
{
    public class RestClient
    {
        private IEnumerable<TemperatureModel> _list; 

        public IEnumerable<TemperatureModel> GetTemperatureCollection()
        {
            TemperatureModel result;

            var webClient = new WebClient();

            webClient.DownloadStringCompleted += ReceiveData;
            webClient.DownloadStringAsync(new Uri("http://temperaturerest.cloudapp.net/Sensor/GetListForView"));

            return _list;
        }

        private void ReceiveData(object sender, DownloadStringCompletedEventArgs e)
        {
            if(e.Error != null)
                return;
            
            _list = JsonConvert.DeserializeObject<IEnumerable<TemperatureModel>>(e.Result);
        }
    }

    public class TemperatureModel
    {
        public int Id { get; set; }
        public string Place { get; set; }
        public double Temperature { get; set; }
        public bool Active { get; set; }
    }
}
